package com.ruoyi.web.controller.common;

import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.web.service.MinioFileService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.List;

@RestController
@RequestMapping("/file")
public class MinioController {

    @Autowired
    private MinioFileService minioFileService;

    /**
     * 上传文件
     */
    @PostMapping(value = "/upload")
    public AjaxResult uploadReport(MultipartFile file, String md5) {
        return minioFileService.uploadReport(file, md5);
    }

    /**
     * 检查是否重复文件
     */
    @PostMapping(value = "/checkFile")
    public AjaxResult checkFile(String md5, String fileName) {
        return minioFileService.checkFile(md5, fileName);
    }

    /**
     * 下载文件，这里没有给授权要注意
     */
    @GetMapping("/download")
    public void download(String saveFileName, HttpServletResponse response, HttpServletRequest request) throws Exception {
        minioFileService.download(saveFileName, response, request);
    }

    /**
     * 删除文件
     */
    @PostMapping("/deleteById")
    public AjaxResult deleteById(String fileId) {
        return minioFileService.deleteById(fileId);
    }

    @PostMapping("/deleteByIds")
    public AjaxResult deleteByIds(@RequestBody List<String> fileIds) {
        return minioFileService.deleteByIds(fileIds);
    }
}

